package com.waiting.rediscluster.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MyController {


    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @RequestMapping("/test")
    public List<String> test() {

        List<String> list = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            String s = getCacheObject("lagou" + i);
            list.add(s);
            //System.out.println(s);
        }

        return list;
    }

    public <T> T getCacheObject(String key)
    {
        ValueOperations<String, T> operation = (ValueOperations<String, T>) redisTemplate.opsForValue();
        return operation.get(key);
    }

}
